//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.item;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.*;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;
import org.jpgolay.gui.iconBar.IconBar;
import org.jpgolay.me.util.*;

public class ItemGUI extends JInternalFrame {

    public ItemGUI() {
        jContentPane = null;
        basicMenu = null;
        iconBar = null;
        jTabbedPane = null;
        infosPanel = null;
        pricePanel = null;
        imagesPanel = null;
        mainPanel = null;
        itemSearch = null;
        idLabelAndTextField = null;
        gtinLabelAndTextField = null;
        designationLabelAndTextField = null;
        jScrollPane = null;
        descriptionTextArea = null;
        familyLabelAndComboBox = null;
        webLabelAndComboBox = null;
        salesUnitLabelAndComboBox = null;
        stockLabelAndTextField = null;
        alertStockLabelAndComboBox = null;
        packagingLabelAndComboBox = null;
        detailsPricePanel = null;
        batchTableViewer = null;
        balancePriceLabelAndTextField = null;
        costPriceLabelAndTextField = null;
        costPriceDetailsLabelAndTextField = null;
        priceList1LabelAndTextField = null;
        priceList2LabelAndTextField = null;
        priceList3LabelAndTextField = null;
        priceList4LabelAndTextField = null;
        promotionLabelAndTextField = null;
        taxLabelAndComboBox = null;
        supplierLabelAndComboBox = null;
        dateLabelAndDateComboBox = null;
        jScrollPane1 = null;
        notesTextArea = null;
        updateTimeLabelAndTextField = null;
        updateUserLabelAndTextField = null;
        jScrollPane2 = null;
        mainImagesPanel = null;
        image1Button = null;
        image2Button = null;
        image3Button = null;
        image4Button = null;
        image5Button = null;
        image6Button = null;
        image7Button = null;
        image8Button = null;
        image9Button = null;
        image10Button = null;
        image1 = null;
        image2 = null;
        image3 = null;
        image4 = null;
        image5 = null;
        image6 = null;
        image7 = null;
        image8 = null;
        image9 = null;
        image10 = null;
        jScrollPane3 = null;
        jSplitPane = null;
        initialize();
    }

    private void initialize() {
        setJMenuBar(getBasicMenu());
        setFrameIcon(new ImageIcon(getClass().getResource("/org/jpgolay/me/images/itemList16x16.png")));
        setTitle("ARTICLE");
        setSize(340, 550);
        setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getIconBar(), "North");
            jContentPane.add(getMainPanel(), "Center");
        }
        return jContentPane;
    }

    private BasicMenu getBasicMenu() {
        if (basicMenu == null) {
            basicMenu = new BasicMenu();
        }
        return basicMenu;
    }

    private IconBar getIconBar() {
        if (iconBar == null) {
            iconBar = new IconBar();
        }
        return iconBar;
    }

    private JTabbedPane getJTabbedPane() {
        if (jTabbedPane == null) {
            jTabbedPane = new JTabbedPane();
            jTabbedPane.setPreferredSize(new Dimension(306, 440));
            jTabbedPane.addTab("Infos", null, getInfosPanel(), null);
            jTabbedPane.addTab("Prix", null, getPricePanel(), null);
            jTabbedPane.addTab("Images", null, getImagesPanel(), null);
        }
        return jTabbedPane;
    }

    private JPanel getInfosPanel() {
        if (infosPanel == null) {
            FlowLayout flowLayout1 = new FlowLayout();
            infosPanel = new JPanel();
            infosPanel.setLayout(flowLayout1);
            flowLayout1.setVgap(2);
            infosPanel.add(getIdLabelAndTextField(), null);
            infosPanel.add(getGtinLabelAndTextField(), null);
            infosPanel.add(getDesignationLabelAndTextField(), null);
            infosPanel.add(getJScrollPane(), null);
            infosPanel.add(getFamilyLabelAndComboBox(), null);
            infosPanel.add(getSalesUnitLabelAndComboBox(), null);
            infosPanel.add(getPackagingLabelAndComboBox(), null);
            infosPanel.add(getStockLabelAndTextField(), null);
            infosPanel.add(getAlertStockLabelAndComboBox(), null);
            infosPanel.add(getWebLabelAndComboBox(), null);
            infosPanel.add(getSupplierLabelAndComboBox(), null);
            infosPanel.add(getJScrollPane1(), null);
        }
        return infosPanel;
    }

    private JPanel getPricePanel() {
        if (pricePanel == null) {
            pricePanel = new JPanel();
            pricePanel.setLayout(new BorderLayout());
            pricePanel.add(getJSplitPane(), "Center");
        }
        return pricePanel;
    }

    private JPanel getImagesPanel() {
        if (imagesPanel == null) {
            imagesPanel = new JPanel();
            imagesPanel.setLayout(new BorderLayout());
            imagesPanel.add(getJScrollPane2(), "Center");
        }
        return imagesPanel;
    }

    private JPanel getMainPanel() {
        if (mainPanel == null) {
            mainPanel = new JPanel();
            mainPanel.setLayout(new BorderLayout());
            mainPanel.add(getItemSearch(), "North");
            mainPanel.add(getJScrollPane3(), "Center");
        }
        return mainPanel;
    }

    private SearchBox getItemSearch() {
        if (itemSearch == null) {
            itemSearch = new SearchBox();
            itemSearch.setPreferredSize(itemSearch.getSize());
            itemSearch.addPropertyChangeListener("icon", new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent e) {
                    itemSearch.setPreferredSize(itemSearch.getSize());
                    getMainPanel().revalidate();
                }
            });
        }
        return itemSearch;
    }

    private LabelAndTextField getIdLabelAndTextField() {
        if (idLabelAndTextField == null) {
            idLabelAndTextField = new LabelAndTextField();
            idLabelAndTextField.setLabel("Code");
        }
        return idLabelAndTextField;
    }

    private LabelAndTextField getGtinLabelAndTextField() {
        if (gtinLabelAndTextField == null) {
            gtinLabelAndTextField = new LabelAndTextField();
            gtinLabelAndTextField.setLabel("GTIN");
        }
        return gtinLabelAndTextField;
    }

    private LabelAndTextField getDesignationLabelAndTextField() {
        if (designationLabelAndTextField == null) {
            designationLabelAndTextField = new LabelAndTextField();
            designationLabelAndTextField.setLabel("D\351signation");
        }
        return designationLabelAndTextField;
    }

    private JScrollPane getJScrollPane() {
        if (jScrollPane == null) {
            jScrollPane = new JScrollPane();
            jScrollPane.setViewportView(getDescriptionTextArea());
            jScrollPane.setPreferredSize(new Dimension(306, 60));
        }
        return jScrollPane;
    }

    private JTextArea getDescriptionTextArea() {
        if (descriptionTextArea == null) {
            descriptionTextArea = new JTextArea();
            descriptionTextArea.setLineWrap(true);
            descriptionTextArea.setWrapStyleWord(true);
            descriptionTextArea.setRows(5);
            descriptionTextArea.setToolTipText("Description de l'article (utiliser sur le web)");
        }
        return descriptionTextArea;
    }

    private LabelAndComboBox getFamilyLabelAndComboBox() {
        if (familyLabelAndComboBox == null) {
            familyLabelAndComboBox = new LabelAndComboBox();
            familyLabelAndComboBox.setLabel("Famille d'article");
        }
        return familyLabelAndComboBox;
    }

    private LabelAndComboBox getWebLabelAndComboBox() {
        if (webLabelAndComboBox == null) {
            webLabelAndComboBox = new LabelAndComboBox();
            webLabelAndComboBox.setLabel("Visible sur le web");
            webLabelAndComboBox.setList(new String[]{
                        "oui", "non"
                    });
        }
        return webLabelAndComboBox;
    }

    private LabelAndComboBox getSalesUnitLabelAndComboBox() {
        if (salesUnitLabelAndComboBox == null) {
            salesUnitLabelAndComboBox = new LabelAndComboBox();
            salesUnitLabelAndComboBox.setLabel("Unit\351 de vente");
            salesUnitLabelAndComboBox.setList(MEUtility.SALES_UNIT);
        }
        return salesUnitLabelAndComboBox;
    }

    private LabelAndTextField getStockLabelAndTextField() {
        if (stockLabelAndTextField == null) {
            stockLabelAndTextField = new LabelAndTextField();
            stockLabelAndTextField.setLabel("Emplacement (stock)");
        }
        return stockLabelAndTextField;
    }

    private LabelAndComboBox getAlertStockLabelAndComboBox() {
        if (alertStockLabelAndComboBox == null) {
            alertStockLabelAndComboBox = new LabelAndComboBox();
            alertStockLabelAndComboBox.setLabel("Stock d'alerte");
            alertStockLabelAndComboBox.setList(MEUtility.PACKAGING);
        }
        return alertStockLabelAndComboBox;
    }

    private LabelAndComboBox getPackagingLabelAndComboBox() {
        if (packagingLabelAndComboBox == null) {
            packagingLabelAndComboBox = new LabelAndComboBox();
            packagingLabelAndComboBox.setLabel("Conditionnement");
            packagingLabelAndComboBox.setList(MEUtility.PACKAGING);
        }
        return packagingLabelAndComboBox;
    }

    private JPanel getDetailsPricePanel() {
        if (detailsPricePanel == null) {
            FlowLayout flowLayout2 = new FlowLayout();
            detailsPricePanel = new JPanel();
            detailsPricePanel.setLayout(flowLayout2);
            flowLayout2.setVgap(2);
            detailsPricePanel.add(getBalancePriceLabelAndTextField(), null);
            detailsPricePanel.add(getCostPriceLabelAndTextField(), null);
            detailsPricePanel.add(getCostPriceDetailsLabelAndTextField(), null);
            detailsPricePanel.add(getPriceList1LabelAndTextField(), null);
            detailsPricePanel.add(getPriceList2LabelAndTextField(), null);
            detailsPricePanel.add(getPriceList3LabelAndTextField(), null);
            detailsPricePanel.add(getPriceList4LabelAndTextField(), null);
            detailsPricePanel.add(getPromotionLabelAndTextField(), null);
            detailsPricePanel.add(getTaxLabelAndComboBox(), null);
            detailsPricePanel.add(getDateLabelAndDateComboBox(), null);
            detailsPricePanel.add(getUpdateTimeLabelAndTextField(), null);
            detailsPricePanel.add(getUpdateUserLabelAndTextField(), null);
        }
        return detailsPricePanel;
    }

    private TableViewer getBatchTableViewer() {
        if (batchTableViewer == null) {
            batchTableViewer = new TableViewer();
            batchTableViewer.setPreferredSize(new Dimension(453, 72));
        }
        return batchTableViewer;
    }

    private LabelAndTextField getBalancePriceLabelAndTextField() {
        if (balancePriceLabelAndTextField == null) {
            balancePriceLabelAndTextField = new LabelAndTextField();
            balancePriceLabelAndTextField.setLabel("Prix d'achat pond\351rer");
            balancePriceLabelAndTextField.getTextField().setHorizontalAlignment(4);
        }
        return balancePriceLabelAndTextField;
    }

    private LabelAndTextField getCostPriceLabelAndTextField() {
        if (costPriceLabelAndTextField == null) {
            costPriceLabelAndTextField = new LabelAndTextField();
            costPriceLabelAndTextField.setLabel("Prix de revient");
            costPriceLabelAndTextField.getTextField().setHorizontalAlignment(4);
        }
        return costPriceLabelAndTextField;
    }

    private LabelAndTextField getCostPriceDetailsLabelAndTextField() {
        if (costPriceDetailsLabelAndTextField == null) {
            costPriceDetailsLabelAndTextField = new LabelAndTextField();
            costPriceDetailsLabelAndTextField.setLabel("(d\351tails)");
            costPriceDetailsLabelAndTextField.setToolTipText("D\351tail du prix de revient (ex: frais de port etc...)");
        }
        return costPriceDetailsLabelAndTextField;
    }

    private LabelAndTextField getPriceList1LabelAndTextField() {
        if (priceList1LabelAndTextField == null) {
            priceList1LabelAndTextField = new LabelAndTextField();
            priceList1LabelAndTextField.setLabel("TG 1 (JGestCom)");
            priceList1LabelAndTextField.getTextField().setHorizontalAlignment(4);
        }
        return priceList1LabelAndTextField;
    }

    private LabelAndTextField getPriceList2LabelAndTextField() {
        if (priceList2LabelAndTextField == null) {
            priceList2LabelAndTextField = new LabelAndTextField();
            priceList2LabelAndTextField.setLabel("Pa (prix d'achat)");
            priceList2LabelAndTextField.getTextField().setHorizontalAlignment(4);
        }
        return priceList2LabelAndTextField;
    }

    private LabelAndTextField getPriceList3LabelAndTextField() {
        if (priceList3LabelAndTextField == null) {
            priceList3LabelAndTextField = new LabelAndTextField();
            priceList3LabelAndTextField.setLabel("TG 2 (web)");
            priceList3LabelAndTextField.getTextField().setHorizontalAlignment(4);
        }
        return priceList3LabelAndTextField;
    }

    private LabelAndTextField getPriceList4LabelAndTextField() {
        if (priceList4LabelAndTextField == null) {
            priceList4LabelAndTextField = new LabelAndTextField();
            priceList4LabelAndTextField.setLabel("TG 3 (web)");
            priceList4LabelAndTextField.getTextField().setHorizontalAlignment(4);
        }
        return priceList4LabelAndTextField;
    }

    private LabelAndTextField getPromotionLabelAndTextField() {
        if (promotionLabelAndTextField == null) {
            promotionLabelAndTextField = new LabelAndTextField();
            promotionLabelAndTextField.setLabel("Promotion");
            promotionLabelAndTextField.getTextField().setHorizontalAlignment(4);
        }
        return promotionLabelAndTextField;
    }

    private LabelAndComboBox getTaxLabelAndComboBox() {
        if (taxLabelAndComboBox == null) {
            taxLabelAndComboBox = new LabelAndComboBox();
            taxLabelAndComboBox.setLabel("TVA");
        }
        return taxLabelAndComboBox;
    }

    private LabelAndComboBox getSupplierLabelAndComboBox() {
        if (supplierLabelAndComboBox == null) {
            supplierLabelAndComboBox = new LabelAndComboBox();
            supplierLabelAndComboBox.setLabel("Fournisseur (habituel)");
        }
        return supplierLabelAndComboBox;
    }

    private LabelAndDateComboBox getDateLabelAndDateComboBox() {
        if (dateLabelAndDateComboBox == null) {
            dateLabelAndDateComboBox = new LabelAndDateComboBox();
            dateLabelAndDateComboBox.setLabel("Date");
        }
        return dateLabelAndDateComboBox;
    }

    private JScrollPane getJScrollPane1() {
        if (jScrollPane1 == null) {
            jScrollPane1 = new JScrollPane();
            jScrollPane1.setViewportView(getNotesTextArea());
            jScrollPane1.setPreferredSize(new Dimension(306, 60));
        }
        return jScrollPane1;
    }

    private JTextArea getNotesTextArea() {
        if (notesTextArea == null) {
            notesTextArea = new JTextArea();
            notesTextArea.setWrapStyleWord(true);
            notesTextArea.setLineWrap(true);
            notesTextArea.setRows(5);
            notesTextArea.setToolTipText("Commentaires");
        }
        return notesTextArea;
    }

    private LabelAndTextField getUpdateTimeLabelAndTextField() {
        if (updateTimeLabelAndTextField == null) {
            updateTimeLabelAndTextField = new LabelAndTextField();
            updateTimeLabelAndTextField.setLabel("Derni\350re modification");
            updateTimeLabelAndTextField.getTextField().setEditable(false);
        }
        return updateTimeLabelAndTextField;
    }

    private LabelAndTextField getUpdateUserLabelAndTextField() {
        if (updateUserLabelAndTextField == null) {
            updateUserLabelAndTextField = new LabelAndTextField();
            updateUserLabelAndTextField.setLabel("Modifi\351 par");
            updateUserLabelAndTextField.getTextField().setEditable(false);
        }
        return updateUserLabelAndTextField;
    }

    private JScrollPane getJScrollPane2() {
        if (jScrollPane2 == null) {
            jScrollPane2 = new JScrollPane();
            jScrollPane2.setViewportView(getMainImagesPanel());
        }
        return jScrollPane2;
    }

    private JPanel getMainImagesPanel() {
        if (mainImagesPanel == null) {
            GridLayout gridLayout3 = new GridLayout();
            mainImagesPanel = new JPanel();
            mainImagesPanel.setLayout(gridLayout3);
            gridLayout3.setColumns(2);
            gridLayout3.setHgap(0);
            gridLayout3.setVgap(0);
            gridLayout3.setRows(5);
            mainImagesPanel.add(getImage1Button(), null);
            mainImagesPanel.add(getImage2Button(), null);
            mainImagesPanel.add(getImage3Button(), null);
            mainImagesPanel.add(getImage4Button(), null);
            mainImagesPanel.add(getImage5Button(), null);
            mainImagesPanel.add(getImage6Button(), null);
            mainImagesPanel.add(getImage7Button(), null);
            mainImagesPanel.add(getImage8Button(), null);
            mainImagesPanel.add(getImage9Button(), null);
            mainImagesPanel.add(getImage10Button(), null);
        }
        return mainImagesPanel;
    }

    private JButton getImage1Button() {
        if (image1Button == null) {
            image1Button = new JButton();
            image1Button.setBorderPainted(true);
            image1Button.setContentAreaFilled(false);
            image1Button.setPreferredSize(new Dimension(148, 148));
            image1Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image1Button.setIcon(actionImage(1));
                        } else {
                            image1Button.setIcon(null);
                            image1 = null;
                        }
                    }
                }
            });
        }
        return image1Button;
    }

    private JButton getImage2Button() {
        if (image2Button == null) {
            image2Button = new JButton();
            image2Button.setBorderPainted(true);
            image2Button.setContentAreaFilled(false);
            image2Button.setPreferredSize(new Dimension(148, 148));
            image2Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image2Button.setIcon(actionImage(2));
                        } else {
                            image2Button.setIcon(null);
                            image2 = null;
                        }
                    }
                }
            });
        }
        return image2Button;
    }

    private JButton getImage3Button() {
        if (image3Button == null) {
            image3Button = new JButton();
            image3Button.setBorderPainted(true);
            image3Button.setContentAreaFilled(false);
            image3Button.setPreferredSize(new Dimension(148, 148));
            image3Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image3Button.setIcon(actionImage(3));
                        } else {
                            image3Button.setIcon(null);
                            image3 = null;
                        }
                    }
                }
            });
        }
        return image3Button;
    }

    private JButton getImage4Button() {
        if (image4Button == null) {
            image4Button = new JButton();
            image4Button.setBorderPainted(true);
            image4Button.setContentAreaFilled(false);
            image4Button.setPreferredSize(new Dimension(148, 148));
            image4Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image4Button.setIcon(actionImage(4));
                        } else {
                            image4Button.setIcon(null);
                            image4 = null;
                        }
                    }
                }
            });
        }
        return image4Button;
    }

    private JButton getImage5Button() {
        if (image5Button == null) {
            image5Button = new JButton();
            image5Button.setBorderPainted(true);
            image5Button.setContentAreaFilled(false);
            image5Button.setPreferredSize(new Dimension(148, 148));
            image5Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image5Button.setIcon(actionImage(5));
                        } else {
                            image5Button.setIcon(null);
                            image5 = null;
                        }
                    }
                }
            });
        }
        return image5Button;
    }

    private JButton getImage6Button() {
        if (image6Button == null) {
            image6Button = new JButton();
            image6Button.setBorderPainted(true);
            image6Button.setContentAreaFilled(false);
            image6Button.setPreferredSize(new Dimension(148, 148));
            image6Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image6Button.setIcon(actionImage(6));
                        } else {
                            image6Button.setIcon(null);
                            image6 = null;
                        }
                    }
                }
            });
        }
        return image6Button;
    }

    private JButton getImage7Button() {
        if (image7Button == null) {
            image7Button = new JButton();
            image7Button.setBorderPainted(true);
            image7Button.setContentAreaFilled(false);
            image7Button.setPreferredSize(new Dimension(148, 148));
            image7Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image7Button.setIcon(actionImage(7));
                        } else {
                            image7Button.setIcon(null);
                            image7 = null;
                        }
                    }
                }
            });
        }
        return image7Button;
    }

    private JButton getImage8Button() {
        if (image8Button == null) {
            image8Button = new JButton();
            image8Button.setBorderPainted(true);
            image8Button.setContentAreaFilled(false);
            image8Button.setPreferredSize(new Dimension(148, 148));
            image8Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image8Button.setIcon(actionImage(8));
                        } else {
                            image8Button.setIcon(null);
                            image8 = null;
                        }
                    }
                }
            });
        }
        return image8Button;
    }

    private JButton getImage9Button() {
        if (image9Button == null) {
            image9Button = new JButton();
            image9Button.setBorderPainted(true);
            image9Button.setContentAreaFilled(false);
            image9Button.setPreferredSize(new Dimension(148, 148));
            image9Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image9Button.setIcon(actionImage(9));
                        } else {
                            image9Button.setIcon(null);
                            image9 = null;
                        }
                    }
                }
            });
        }
        return image9Button;
    }

    private JButton getImage10Button() {
        if (image10Button == null) {
            image10Button = new JButton();
            image10Button.setBorderPainted(true);
            image10Button.setContentAreaFilled(false);
            image10Button.setPreferredSize(new Dimension(148, 148));
            image10Button.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                    if (getIdLabelAndTextField().getTextField().isEditable()) {
                        if (e.getButton() == 1) {
                            image10Button.setIcon(actionImage(10));
                        } else {
                            image10Button.setIcon(null);
                            image10 = null;
                        }
                    }
                }
            });
        }
        return image10Button;
    }

    private JScrollPane getJScrollPane3() {
        if (jScrollPane3 == null) {
            jScrollPane3 = new JScrollPane();
            jScrollPane3.setHorizontalScrollBarPolicy(31);
            jScrollPane3.setViewportView(getJTabbedPane());
            jScrollPane3.setPreferredSize(new Dimension(309, 440));
        }
        return jScrollPane3;
    }

    private JSplitPane getJSplitPane() {
        if (jSplitPane == null) {
            jSplitPane = new JSplitPane();
            jSplitPane.setOrientation(0);
            jSplitPane.setTopComponent(getBatchTableViewer());
            jSplitPane.setBottomComponent(getDetailsPricePanel());
            jSplitPane.setDividerLocation(72);
            jSplitPane.setOneTouchExpandable(true);
            jSplitPane.setDividerSize(6);
        }
        return jSplitPane;
    }

    private ImageIcon actionImage(int i) {
        if (photoFileChooser()) {
            byte image[] = (byte[]) null;
            if ((image = loadImage(selectedFile.getAbsolutePath())) == null) {
                JOptionPane.showMessageDialog(this, "L'image s\351l\351ctionn\351e est trop grande !");
                return null;
            }
            switch (i) {
                case 1: // '\001'
                    image1 = image;
                    break;

                case 2: // '\002'
                    image2 = image;
                    break;

                case 3: // '\003'
                    image3 = image;
                    break;

                case 4: // '\004'
                    image4 = image;
                    break;

                case 5: // '\005'
                    image5 = image;
                    break;

                case 6: // '\006'
                    image6 = image;
                    break;

                case 7: // '\007'
                    image7 = image;
                    break;

                case 8: // '\b'
                    image8 = image;
                    break;

                case 9: // '\t'
                    image9 = image;
                    break;

                case 10: // '\n'
                    image10 = image;
                    break;
            }
            return resizeImageIcon(new ImageIcon(image));
        } else {
            JOptionPane.showMessageDialog(this, "Aucune image s\351l\351ctionn\351e !");
            return null;
        }
    }

    private ImageIcon resizeImageIcon(ImageIcon tmpIcon) {
        if (tmpIcon.getIconWidth() > 148) {
            return new ImageIcon(tmpIcon.getImage().getScaledInstance(148, -1, 1));
        } else {
            return tmpIcon;
        }
    }

    private boolean photoFileChooser() {
        if (fileChooser == null) {
            fileChooser = new JFileChooser();
            fileChooser.addChoosableFileFilter(new ImageFilter());
            fileChooser.setAcceptAllFileFilterUsed(false);
            fileChooser.setAccessory(new ImagePreview(fileChooser));
        }
        int result = fileChooser.showOpenDialog(this);
        if (result == 0) {
            selectedFile = fileChooser.getSelectedFile();
            return true;
        } else {
            return false;
        }
    }

    private byte[] loadImage(String path) {
        try {
            File f = new File(path);
            int len = (int) f.length();
            byte b[] = new byte[len];
            FileInputStream fin = new FileInputStream(f);
            for (int offset = 0; offset < len; offset += fin.read(b, offset, len - offset));
            fin.close();
            if (b.length > 55000) {
                b = (byte[]) null;
            }
            return b;
        } catch (IOException e) {
            return null;
        }
    }

    public BasicMenu getMenuPanel() {
        return getBasicMenu();
    }

    public IconBar getIconBarPanel() {
        return getIconBar();
    }

    public byte[] getImage1() {
        return image1;
    }

    public void setImage1(byte image1[]) {
        this.image1 = image1;
        if (image1 != null) {
            image1Button.setIcon(resizeImageIcon(new ImageIcon(image1)));
        } else {
            image1Button.setIcon(null);
        }
    }

    public byte[] getImage10() {
        return image10;
    }

    public void setImage10(byte image10[]) {
        this.image10 = image10;
        if (image10 != null) {
            image10Button.setIcon(resizeImageIcon(new ImageIcon(image10)));
        } else {
            image10Button.setIcon(null);
        }
    }

    public byte[] getImage2() {
        return image2;
    }

    public void setImage2(byte image2[]) {
        this.image2 = image2;
        if (image2 != null) {
            image2Button.setIcon(resizeImageIcon(new ImageIcon(image2)));
        } else {
            image2Button.setIcon(null);
        }
    }

    public byte[] getImage3() {
        return image3;
    }

    public void setImage3(byte image3[]) {
        this.image3 = image3;
        if (image3 != null) {
            image3Button.setIcon(resizeImageIcon(new ImageIcon(image3)));
        } else {
            image3Button.setIcon(null);
        }
    }

    public byte[] getImage4() {
        return image4;
    }

    public void setImage4(byte image4[]) {
        this.image4 = image4;
        if (image4 != null) {
            image4Button.setIcon(resizeImageIcon(new ImageIcon(image4)));
        } else {
            image4Button.setIcon(null);
        }
    }

    public byte[] getImage5() {
        return image5;
    }

    public void setImage5(byte image5[]) {
        this.image5 = image5;
        if (image5 != null) {
            image5Button.setIcon(resizeImageIcon(new ImageIcon(image5)));
        } else {
            image5Button.setIcon(null);
        }
    }

    public byte[] getImage6() {
        return image6;
    }

    public void setImage6(byte image6[]) {
        this.image6 = image6;
        if (image6 != null) {
            image6Button.setIcon(resizeImageIcon(new ImageIcon(image6)));
        } else {
            image6Button.setIcon(null);
        }
    }

    public byte[] getImage7() {
        return image7;
    }

    public void setImage7(byte image7[]) {
        this.image7 = image7;
        if (image7 != null) {
            image7Button.setIcon(resizeImageIcon(new ImageIcon(image7)));
        } else {
            image7Button.setIcon(null);
        }
    }

    public byte[] getImage8() {
        return image8;
    }

    public void setImage8(byte image8[]) {
        this.image8 = image8;
        if (image8 != null) {
            image8Button.setIcon(resizeImageIcon(new ImageIcon(image8)));
        } else {
            image8Button.setIcon(null);
        }
    }

    public byte[] getImage9() {
        return image9;
    }

    public void setImage9(byte image9[]) {
        this.image9 = image9;
        if (image9 != null) {
            image9Button.setIcon(resizeImageIcon(new ImageIcon(image9)));
        } else {
            image9Button.setIcon(null);
        }
    }

    public SearchBox getItemSearchBox() {
        return getItemSearch();
    }

    public String getId() {
        return getIdLabelAndTextField().getVal();
    }

    public void setId(String txt) {
        getIdLabelAndTextField().setVal(txt);
    }

    public String getGtin() {
        return getGtinLabelAndTextField().getVal();
    }

    public void setGtin(String txt) {
        getGtinLabelAndTextField().setVal(txt);
    }

    public String getDesignation() {
        return getDesignationLabelAndTextField().getVal();
    }

    public void setDesignation(String txt) {
        getDesignationLabelAndTextField().setVal(txt);
    }

    public String getDescription() {
        return getDescriptionTextArea().getText();
    }

    public void setDescription(String txt) {
        getDescriptionTextArea().setText(txt);
    }

    public String getFamily() {
        return getFamilyLabelAndComboBox().getSelectedString();
    }

    public void setFamily(String txt) {
        getFamilyLabelAndComboBox().setSelectedString(txt);
    }

    public void setFamilyList(String list[]) {
        getFamilyLabelAndComboBox().setList(list);
    }

    public void setFamilyIndex(int index) {
        getFamilyLabelAndComboBox().setSelectedIndex(index);
    }

    public String getWeb() {
        return getWebLabelAndComboBox().getSelectedString();
    }

    public void setWeb(String txt) {
        getWebLabelAndComboBox().setSelectedString(txt);
    }

    public void setWebIndex(int index) {
        getWebLabelAndComboBox().setSelectedIndex(index);
    }

    public String getSalesUnit() {
        return getSalesUnitLabelAndComboBox().getSelectedString();
    }

    public void setSalesUnit(String txt) {
        getSalesUnitLabelAndComboBox().setSelectedString(txt);
    }

    public void setSalesUnitIndex(int index) {
        getSalesUnitLabelAndComboBox().setSelectedIndex(index);
    }

    public String getStockPlace() {
        return getStockLabelAndTextField().getVal();
    }

    public void setStockPlace(String txt) {
        getStockLabelAndTextField().setVal(txt);
    }

    public String getAlertStock() {
        return getAlertStockLabelAndComboBox().getSelectedString();
    }

    public void setAlertStock(String txt) {
        getAlertStockLabelAndComboBox().setSelectedString(txt);
    }

    public void setAlertStockIndex(int index) {
        getAlertStockLabelAndComboBox().setSelectedIndex(index);
    }

    public String getPackaging() {
        return getPackagingLabelAndComboBox().getSelectedString();
    }

    public void setPackaging(String txt) {
        getPackagingLabelAndComboBox().setSelectedString(txt);
    }

    public void setPackagingIndex(int index) {
        getPackagingLabelAndComboBox().setSelectedIndex(index);
    }

    public TableViewer getBatchTable() {
        return getBatchTableViewer();
    }

    public String getBalancePrice() {
        return getBalancePriceLabelAndTextField().getVal();
    }

    public void setBalancePrice(String txt) {
        getBalancePriceLabelAndTextField().setVal(txt);
    }

    public String getCostPrice() {
        return getCostPriceLabelAndTextField().getVal();
    }

    public void setCostPrice(String txt) {
        getCostPriceLabelAndTextField().setVal(txt);
    }

    public String getCostPriceDetails() {
        return getCostPriceDetailsLabelAndTextField().getVal();
    }

    public void setCostPriceDetails(String txt) {
        getCostPriceDetailsLabelAndTextField().setVal(txt);
    }

    public String getPriceList1() {
        return getPriceList1LabelAndTextField().getVal();
    }

    public void setPriceList1(String txt) {
        getPriceList1LabelAndTextField().setVal(txt);
    }

    public String getPriceList2() {
        return getPriceList2LabelAndTextField().getVal();
    }

    public void setPriceList2(String txt) {
        getPriceList2LabelAndTextField().setVal(txt);
    }

    public String getPriceList3() {
        return getPriceList3LabelAndTextField().getVal();
    }

    public void setPriceList3(String txt) {
        getPriceList3LabelAndTextField().setVal(txt);
    }

    public String getPriceList4() {
        return getPriceList4LabelAndTextField().getVal();
    }

    public void setPriceList4(String txt) {
        getPriceList4LabelAndTextField().setVal(txt);
    }

    public String getPromotion() {
        return getPromotionLabelAndTextField().getVal();
    }

    public void setPromotion(String txt) {
        getPromotionLabelAndTextField().setVal(txt);
    }

    public int getTax() {
        return getTaxLabelAndComboBox().getSelectedIndex();
    }

    public void setTax(int index) {
        getTaxLabelAndComboBox().setSelectedIndex(index);
    }

    public void setTaxList(String list[]) {
        getTaxLabelAndComboBox().setList(list);
    }

    public String getSupplier() {
        return getSupplierLabelAndComboBox().getSelectedString();
    }

    public void setSupplier(String txt) {
        getSupplierLabelAndComboBox().setSelectedString(txt);
    }

    public void setSupplierList(String list[]) {
        getSupplierLabelAndComboBox().setList(list);
    }

    public void setSupplierIndex(int index) {
        getSupplierLabelAndComboBox().setSelectedIndex(index);
    }

    public String getDate() {
        return getDateLabelAndDateComboBox().getDate();
    }

    public void setDate(String txt) {
        getDateLabelAndDateComboBox().setDate(txt);
    }

    public String getNotes() {
        return getNotesTextArea().getText();
    }

    public void setNotes(String txt) {
        getNotesTextArea().setText(txt);
    }

    public String getUpdateTime() {
        return getUpdateTimeLabelAndTextField().getVal();
    }

    public void setUpdateTime(String txt) {
        getUpdateTimeLabelAndTextField().setVal(txt);
    }

    public String getUpdateUser() {
        return getUpdateUserLabelAndTextField().getVal();
    }

    public void setUpdateUser(String txt) {
        getUpdateUserLabelAndTextField().setVal(txt);
    }

    public void cleanField() {
        setImage1(null);
        setImage10(null);
        setImage2(null);
        setImage3(null);
        setImage4(null);
        setImage5(null);
        setImage6(null);
        setImage7(null);
        setImage8(null);
        setImage9(null);
        setId("");
        setGtin("");
        setDesignation("");
        setDescription("");
        setFamilyIndex(0);
        setWebIndex(0);
        setSalesUnitIndex(0);
        setStockPlace("");
        setAlertStockIndex(0);
        setPackagingIndex(0);
        setBalancePrice("0.00");
        setCostPrice("0.00");
        setCostPriceDetails("");
        setPriceList1("0.00");
        setPriceList2("0.00");
        setPriceList3("0.00");
        setPriceList4("0.00");
        setPromotion("0.00");
        setTax(0);
        setSupplierIndex(0);
        setDate("");
        setNotes("");
        setUpdateTime("");
        setUpdateUser("");
        setTitle("ARTICLE");
    }

    public void setEnabledField(boolean b) {
        getIdLabelAndTextField().getTextField().setEditable(b);
        getGtinLabelAndTextField().getTextField().setEditable(b);
        getDesignationLabelAndTextField().getTextField().setEditable(b);
        getDescriptionTextArea().setEditable(b);
        getFamilyLabelAndComboBox().getComboBox().setEnabled(b);
        getWebLabelAndComboBox().getComboBox().setEnabled(b);
        getSalesUnitLabelAndComboBox().getComboBox().setEnabled(b);
        getStockLabelAndTextField().getTextField().setEditable(b);
        getAlertStockLabelAndComboBox().getComboBox().setEnabled(b);
        getPackagingLabelAndComboBox().getComboBox().setEnabled(b);
        getBalancePriceLabelAndTextField().getTextField().setEditable(b);
        getCostPriceLabelAndTextField().getTextField().setEditable(b);
        getCostPriceDetailsLabelAndTextField().getTextField().setEditable(b);
        getPriceList1LabelAndTextField().getTextField().setEditable(b);
        getPriceList2LabelAndTextField().getTextField().setEditable(b);
        getPriceList3LabelAndTextField().getTextField().setEditable(b);
        getPriceList4LabelAndTextField().getTextField().setEditable(b);
        getPromotionLabelAndTextField().getTextField().setEditable(b);
        getTaxLabelAndComboBox().getComboBox().setEnabled(b);
        getSupplierLabelAndComboBox().getComboBox().setEnabled(b);
        getDateLabelAndDateComboBox().setEnabledDateComboBox(b);
        getNotesTextArea().setEditable(b);
    }
    private JPanel jContentPane;
    private BasicMenu basicMenu;
    private IconBar iconBar;
    private JTabbedPane jTabbedPane;
    private JPanel infosPanel;
    private JPanel pricePanel;
    private JPanel imagesPanel;
    private JPanel mainPanel;
    private SearchBox itemSearch;
    private LabelAndTextField idLabelAndTextField;
    private LabelAndTextField gtinLabelAndTextField;
    private LabelAndTextField designationLabelAndTextField;
    private JScrollPane jScrollPane;
    private JTextArea descriptionTextArea;
    private LabelAndComboBox familyLabelAndComboBox;
    private LabelAndComboBox webLabelAndComboBox;
    private LabelAndComboBox salesUnitLabelAndComboBox;
    private LabelAndTextField stockLabelAndTextField;
    private LabelAndComboBox alertStockLabelAndComboBox;
    private LabelAndComboBox packagingLabelAndComboBox;
    private JPanel detailsPricePanel;
    private TableViewer batchTableViewer;
    private LabelAndTextField balancePriceLabelAndTextField;
    private LabelAndTextField costPriceLabelAndTextField;
    private LabelAndTextField costPriceDetailsLabelAndTextField;
    private LabelAndTextField priceList1LabelAndTextField;
    private LabelAndTextField priceList2LabelAndTextField;
    private LabelAndTextField priceList3LabelAndTextField;
    private LabelAndTextField priceList4LabelAndTextField;
    private LabelAndTextField promotionLabelAndTextField;
    private LabelAndComboBox taxLabelAndComboBox;
    private LabelAndComboBox supplierLabelAndComboBox;
    private LabelAndDateComboBox dateLabelAndDateComboBox;
    private JScrollPane jScrollPane1;
    private JTextArea notesTextArea;
    private LabelAndTextField updateTimeLabelAndTextField;
    private LabelAndTextField updateUserLabelAndTextField;
    private JScrollPane jScrollPane2;
    private JPanel mainImagesPanel;
    private JButton image1Button;
    private JButton image2Button;
    private JButton image3Button;
    private JButton image4Button;
    private JButton image5Button;
    private JButton image6Button;
    private JButton image7Button;
    private JButton image8Button;
    private JButton image9Button;
    private JButton image10Button;
    private byte image1[];
    private byte image2[];
    private byte image3[];
    private byte image4[];
    private byte image5[];
    private byte image6[];
    private byte image7[];
    private byte image8[];
    private byte image9[];
    private byte image10[];
    private JScrollPane jScrollPane3;
    private JSplitPane jSplitPane;
    private JFileChooser fileChooser;
    private File selectedFile;
}
